package com.sky.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.sky.annotation.AutoFill;
import com.sky.constant.MessageConstant;
import com.sky.dto.UserLoginDTO;
import com.sky.entity.User;
import com.sky.enumeration.OperationType;
import com.sky.exception.LoginFailedException;
import com.sky.mapper.UserMapper;
import com.sky.properties.WeChatProperties;
import com.sky.service.UserService;
import com.sky.utils.HttpClientUtil;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.security.auth.login.LoginException;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    public static final String LOGIN_URL="https://api.weixin.qq.com/sns/jscode2session";
    @Autowired
    private UserMapper userMapper;

    // 登录
    @Override
    public User login(UserLoginDTO userLoginDTO) {
        User user = userMapper.selectByOpenId(userLoginDTO);
        return user;
    }

    @Override
    public Boolean regist(UserLoginDTO userLoginDTO) {
        Integer i = userMapper.selectUserName(userLoginDTO);
        if(i>0){
            return false;
        }
        else{
            userLoginDTO.setCreateTime(LocalDateTime.now());
            userMapper.regist(userLoginDTO);
            return true;
        }
    }
}
